#include <error.h>
#include <stdint.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>                   // S_ISDIR et al
#include <ctime>
#include <cstdio>
#include <fstream>
#include <iostream>
#include <map>
#include <memory>
#include <string>
#include <vector>

using namespace std;

/**
 * Examples:
 * path                parent path         child name
 * /                   /
 * /foo                /                   foo
 * /foo/bar            /foo/               bar
 * /foo/bar/           /foo/               bar
 * /foo/bar/pole/      /foo/bar/           pole
 */
int
splitPath(
    string const& path,
    string& parentPath,
    string& childName
)
{
    if(path.empty() || path[0] != '/' || path.find('\0'))
    {
        // Path must begin with a slash.  Path must contain no nulls.
        return -EINVAL;
    }
    // Strip the trailing separator, if any.
    string::size_type end;
    if( path.size() >= 2 && *(path.end()-1) == '/' )
        end = path.size() - 1;
    else
        end = path.size();
    size_t i = path.rfind('/', end - 1);
    if(i == string::npos)
    {
        // Path must contain at least one slash.
        return -EINVAL;
    }
    // Split the path into two components. parentPath always gets a
    // trailing separator.
    ++i;
    // I points to the start of the child name.
    parentPath = path.substr(0, i);
    childName = path.substr(i, end-i);
    
    /* Debug output
    printf("`%s'  `%s'   i=%2d  end=%2d\n",
        parentPath.c_str(), childName.c_str(), i, end);
    */
    return 0;
}


int main()
{
    for(;;)
    {
        string line;
        getline(cin, line);
        if(cin.rdstate() != ios::goodbit) //& (ios::failbit | ios::badbit | ios::eofbit))
            break;
        string const& path = line;
        string parentPath, childName;
        int r = splitPath(path, parentPath, childName);
        if(r)
        {
            error(0, r, "splitPath");
        }
    }
    return 0;
}

